package com.ytb.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ytb.mapper.eventMapper;
import com.ytb.pojo.events;
import com.ytb.pojo.user;
import com.ytb.service.IEventService;
import com.ytb.service.IUserService;
import com.ytb.utils.MybatisPlusUtils;
import com.ytb.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class eventServiceImpl implements IEventService {
    @Autowired
    private eventMapper eMapper;
    @Override
    public Result getSwapper() {
        LambdaQueryWrapper<events> lqw = Wrappers.lambdaQuery();
        lqw.eq(events::getIsCarousel,1);
        List<events> events = eMapper.selectList(lqw);
        if (events == null)
        {
            return Result.FAIL("轮播图不存在");
        }
        for (com.ytb.pojo.events event : events) {
            event.setCTime(null);
            event.setUTime(null);
            event.setUUserId(null);
            event.setCUserId(null);
        }
        return Result.SUCCESS(events);
    }

    //首页随机活动
    @Override
    public Result getRandom() {
        List<events> randomList = MybatisPlusUtils.getAny(eMapper, null, 2);
        for (events events : randomList) {
            events.setUTime(null);
            events.setCTime(null);
            events.setUUserId(null);
            events.setCUserId(null);
        }
        return Result.SUCCESS(randomList);
    }


}
